<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>保险公司 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="insCompMgr" title="保险公司管理" lselected="true">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">保险公司名称</div>
                                <div class="field">
                                    <input name="compNm" id="compNm" type="text" class="ui-textbox" value="">
                                </div>
                            </div>
                            <div class="formBtns notRight">
                                <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                                <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                                <sys:funcAuth resCd="insCompUID">
                                    <span id="addBtn" class="sq-button sq-button-round">新增</span>
                                    <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                                    <span id="delBtn" class="sq-button sq-button-round">删除</span>
                                </sys:funcAuth>

                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="ligergrid1" class="sq-grid"></div>
            </div>
            <div tabid="insBchCompMgr" title="保险支公司管理">
                <iframe frameborder="0" name="insBchCompMgr" id="insBchCompMgr" src="<%=path%>/insurance/insCompInfo/toListPage.do?compLvl=2"></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid = null;
    var pageInApp = {};
    $(function () {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (tabid == "insBchCompMgr") {
                	var row = pageInApp.seletedCompRow;
                	if(row){
                		var oldUrl=pageInTab.getTabItemSrc(tabid);
                        var newUrl = "<%=path%>/insurance/insCompInfo/toListPage.do?compLvl=2&compPid=" + row.id;
                        if(newUrl!=oldUrl){
    	                    pageInTab.setTabItemSrc(tabid, newUrl);
    	                    pageInTab.reload(tabid);
                        }
                	}
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insCompInfo/initList.do?compLvl=1',
            method: 'get',
            columns: [
                {display: '公司名称', name: 'compNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '联系人', name: 'lmNm', width: 100, align: 'left', enabledSort: false},
                {display: '联系电话', name: 'lmTel', width: 100, align: 'left', enabledSort: false},
                {display: '公司地址', name: 'compAddr', minWidth: 100, align: 'left', enabledSort: false},
                {display: '备注', name: 'compRem', minWidth: 100, align: 'left', enabledSort: false},
                {display: '操作', name: '', width: 150, align: 'center', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='<a class="sq-button-hasicon" style="cursor:pointer;" href="javascript:;" onclick="searchDtl(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_1"></i>查看</a>';
                        h+='<a class="sq-button-hasicon" style="cursor:pointer;" href="javascript:;" onclick="searchSubComp(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_1"></i>分支</a>';
                        return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            onSelectRow: function (rowdata,rowNum,rowEl) {
                $.extend(true, pageInApp, {seletedCompRow: rowdata});
            },
            onUnSelectRow: function (rowdata) {
                $.extend(true, pageInApp, {seletedCompRow: null});
            }
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
        });

        var callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 800,
                height: 450,
                title: '新增保险公司',
                url: '<%=path%>/insurance/insCompInfo/toAddPage.do'
            });
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            $.ligerDialog.open({
                width: 800,
                height: 450,
                title: '修改保险公司',
                url: '<%=path%>/insurance/insCompInfo/toModifyPage.do?id=' + _id
            });
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm("是否确认删除选中的保险公司，同时删除保险公司下所有支公司?", function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insCompInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

    //查看
    function searchDtl(id){
        $.ligerDialog.open({
            width: 800,
            height: 450,
            title: '查看保险公司详情',
            url: '<%=path%>/insurance/insCompInfo/toCompDtlPage.do?id=' + id
        });
    }

    //查看分支
    function searchSubComp(pid){
        var tabId="insBchCompMgr";
        var newUrl = "<%=path%>/insurance/insCompInfo/toListPage.do?compLvl=2&compPid=" + pid;
        pageInTab.selectTabItem(tabId);
        pageInTab.setTabItemSrc(tabId, newUrl);
    }

</script>

</body>
</html>
